﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entitty;

namespace ClassLibrary.DAO
{
    public class TblNoiDungTrangHomeDAO
    {
          private DBService _db = null;
          public TblNoiDungTrangHomeDAO(string ConnectionString)
         {
            _db = new DBService(ConnectionString);
         }
          public DataTable Insert(TblNoiDungTrangHome noidungHome, int Mode)
          {
              DataTable dt = null;
              try
              {

                  dt = _db.ExeSP_DataTable("TblNoiDungTrangHome_InsUp",
                      new string[] { "@id", "@NoiDung_Cot1", "@NoiDung_Cot2", "@NoiDung_Cot3", "@Noidung", "@mode" },
                      new object[] { noidungHome.Id, noidungHome.NoiDung_Cot1, noidungHome.NoiDung_Cot2, noidungHome.NoiDung_Cot3, noidungHome.Noidung, Mode },
                      CommandType.StoredProcedure);

              }
              catch (Exception ex)
              {
                  throw ex;
              }
              return dt;
          }

          public DataTable GetNoiDung()
          {
              DataTable dt = null;
              dt = _db.ExeSP_DataTable("select top(1) * from TblNoiDungTrangHome order by id desc ", false, CommandType.Text);
              return dt;
          }

          public TblNoiDungTrangHome GetNoiDung_ByID(int id)
          {
              TblNoiDungTrangHome noidungHome = new TblNoiDungTrangHome();
              try
              {
                  DataTable dt = null;
                  dt = _db.ExeSP_DataTable("select top(1) * from TblNoiDungTrangHome where id = @id order by id desc", 
                      new string[]{"@id"}, new object[]{id}, CommandType.Text);
                  foreach (DataRow dr in dt.Rows)
                  {
                      noidungHome.Noidung = dr["Noidung"].ToString();
                      noidungHome.NoiDung_Cot1 = dr["NoiDung_Cot1"].ToString();
                      noidungHome.NoiDung_Cot2 = dr["NoiDung_Cot2"].ToString();
                      noidungHome.NoiDung_Cot3 = dr["NoiDung_Cot3"].ToString();
                      noidungHome.Id = id;
                  }
              }
              catch (Exception e)
              {
                  throw e;
              }
              return noidungHome;
          }
    }
}
